<?php

class NetModel extends CFormModel
{
    public static $_models = array();
    public $javaApi = array();
    public function init()
    {
        $this->javaApi = Yii::app()->params['scripts'];
    }
    public function attributeNames()
    {
        return array();
    }

    public static function model($className=__CLASS__)
    {
        if(isset(self::$_models[$className]))
            return self::$_models[$className];
        else
        {
            $model=self::$_models[$className]=new $className(null);
            $model->attachBehaviors($model->behaviors());
            return $model;
        }
    }

    public function setResult($data)
    {
        if($data)
        {
            $data      = Yii::app()->controller->formatResult($data);
            $content   = json_encode($data);
            $spentTime = intval((microtime(true) - YII_BEGIN_TIME)*1000);
            $log       = $_SERVER['REQUEST_METHOD'].' '.HttpLib::getRemoteIp().' '.MOBILEOS.' '.APPVERSION .' model '.get_class($this).' request params are '.json_encode($_REQUEST).' result is '.$content.' spent time '.$spentTime.' ms';
            Yii::trace($log,'php.echo');
            if($data['success'] === 0)
                Yii::log($log,'warning','php.warning.model');
            Yii::log(MOBILEOS.' '.APPVERSION .' model '.get_class($this).' spent time '.$spentTime.' ms',CLogger::LEVEL_INFO);
            echo $content;
            Yii::app()->end();
        }
    }
}
